const enterpriseVue = new Vue({
  el: '#app',
  data() {
    return {
      pickerOptions: pickerOptions,
      rules: {
        Article_Name: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
        Brand_SerialNumber: [{ required: true, message: '请选择商品品牌', trigger: 'change' }],
        Category_SerialNumber: [{ required: true, message: '请选择商品类别', trigger: 'change' }],
        Series_SerialNumber: [{ required: true, message: '请选择商品系列', trigger: 'change' }],
        Item_SerialNumber: [{ required: true, message: '请选择商品款型', trigger: 'change' }],
        Unit_Price: [{ required: true, message: '请输入吊牌价', trigger: 'blur' }],
        Picture_URL: [{ required: true, message: '请输入图片地址', trigger: 'blur' }],
        // Size: [{ required: true, message: '请输入SKU尺寸', trigger: 'blur' }],
        // Weight: [{ required: true, message: '请输入SKU重量', trigger: 'blur' }],
        // Weight_Unit: [{ required: true, message: '请选择SKU单位', trigger: 'change' }],
        // Package_Quantity: [{ required: true, message: '请输入小包装数量', trigger: 'blur' }],
        // SKU_Package_Size: [{ required: true, message: '请输入SKU包装尺寸', trigger: 'blur' }],
        // Carton_Quantity: [{ required: true, message: '请输入大包装数量', trigger: 'blur' }]
      },
      brand: [],
      category: [],
      series: [],
      item: [],
      unit: [],
      fileList: [],
      fileList1: [],
      fileList3: [],
      dialogImageUrl: '',
      dialogVisible: false,
      dialogVisible1: false,
      form: {
        Article_SerialNumber: "",
        Article_Name: '',
        Brand_SerialNumber: '',
        Category_SerialNumber: '',
        Series_SerialNumber: '',
        Item_SerialNumber: '',
        Size: '',
        Unit_Price: '',
        Picture_URL: '',
        Weight: '',
        Weight_Unit: '',
        Package_Quantity: '',
        SKU_Package_Size: '',
        Carton_Quantity: '',
        Children: {
          article_pic: []
        }
      },
      loading: false
    }
  },
  mounted() {
    const Article_SerialNumber = sessionStorage.getItem("Article_SerialNumber")
    this.getData(Article_SerialNumber)
  },
  methods: {
    getData(Article_SerialNumber) {
      let _this = this;
      $.ajax({
        url: DomainName + '/ShopBrand',
        type: 'GET',
        data: { action: "jQueryAjax" },
        success: function (res) {
          res = res.filter(function (item) {
            return item.Row_Status != '1'
          })
          for (let i = 0; i < res.length; i++) {
            _this.brand.push(res[i].Brand_Name);
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
      $.ajax({
        url: DomainName + '/ArticleUnit',
        type: 'GET',
        data: { action: "jQueryAjax", },
        success: function (res) {
          res = res.filter(function (item) {
            return item.Row_Status != '1'
          })
          for (let i = 0; i < res.length; i++) {
            _this.unit.push(res[i].Unit);
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
      $.ajax({
        url: DomainName + '/ShopCategory',
        type: 'GET',
        data: { action: "jQueryAjax" },
        success: function (res) {
          res = res.filter(function (item) {
            return item.Row_Status != '1'
          })
          for (let i = 0; i < res.length; i++) {
            _this.category.push(res[i].Category_Name);
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
      $.ajax({
        url: DomainName + '/ShopSeries',
        type: 'GET',
        data: { action: "jQueryAjax" },
        success: function (res) {
          res = res.filter(function (item) {
            return item.Row_Status != '1'
          })
          for (let i = 0; i < res.length; i++) {
            _this.series.push(res[i].Series_Name);
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
      $.ajax({
        url: DomainName + '/ShopItem',
        type: 'GET',
        data: { action: "jQueryAjax" },
        success: function (res) {
          res = res.filter(function (item) {
            return item.Row_Status != '1'
          })
          for (let i = 0; i < res.length; i++) {
            _this.item.push(res[i].Item_Name);
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
      $.ajax({
        url: DomainName + '/ArticleInfoId',
        type: 'POST',
        data: {
          Data: Article_SerialNumber
        },
        success: function (res) {
          _this.form = res.article_info[0]
          if (_this.form.Children.article_pic && _this.form.Children.article_pic.length != 0) {
            _this.form.Children.article_pic.forEach(item => {
              if (item.Picture_Type == 0) {
                _this.fileList.push({
                  pic: item.Picture_Url
                })
              } else if (item.Picture_Type == 1) {
                _this.fileList1.push({
                  pic: item.Picture_Url
                })
              }
            });

          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    //查看图片
    handlePictureCardPreview(file) {
      this.dialogVisible = true
      this.dialogImageUrl = file
    },
  }
})